import {HttpClient} from '@angular/common/http';
import {Injectable} from '@angular/core';
import {Observable} from "rxjs/Observable";

@Injectable()
export class MessageListProvider {
    private url = '/message/v1/app/list';
    private deleteUrl='/message/v1/app/one';
    private prevUrl = '/message/v1/app/preview';

    constructor(public http: HttpClient) {

    }

    // 获取消息列表
    getMessageList(keyword,type,pageNum=0,pageSize=0): Observable<any> {
        let typeStr='';
        if(keyword){
            type[0]?typeStr=typeStr+'&typeIds='+type[0]:typeStr='';
            return this.http.get(this.url+'?keyword='+keyword+typeStr)
        }else{
            type[0]?typeStr=typeStr+'?typeIds='+type[0]:typeStr='';
            return this.http.get(this.url+typeStr)
        }
    }

    // 获取消息预览信息
    getMsgOverview(id): Observable<any> {
        return this.http.get(this.prevUrl+'?typeId='+id)
    }

    // 删除消息
    deleteMessage(id):Observable<any>{
        return this.http.delete(this.deleteUrl+'?messageId='+id,{responseType:'text'});
    }
}
